require 'if_it_werent_4_AR'

class Iitw4arGenerator < Rails::Generators::Base
  def create_models_with_storages
    schema = IfItWerent4AR::Initialization::get_schema
    schema.each_pair do |table_name, fields_with_types|
      create_file "app/models/#{table_name.underscore}.rb", <<-FILE
class #{table_name.camelize} < IfItWerent4AR::Base
end
      FILE

      create_file "db/#{table_name.underscore}_storage.csv", <<-FILE
#{fields_with_types.keys.join(IfItWerent4AR::FileOp::DELIMITER)}
      FILE
    end
  end

  def create_initializer_file
    create_file "config/initializers/itw4ar.rb", <<-FILE
require 'if_it_werent_4_AR'

IfItWerent4AR::Initialization::init_mapping
    FILE
  end
end
